//
//  SearchView.swift
//  MicroBlog
//
//  Created by Apple on 16/9/19.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

class SearchView: UIView {

    @IBOutlet weak var searchButton: UIButton!

    @IBOutlet weak var searchTextField: UITextField!
    
    @IBOutlet weak var searchTextFieldRightConstranit: NSLayoutConstraint!
    
    @IBAction func editBegin(_ sender: AnyObject) {
        searchTextFieldRightConstranit.constant = searchButton.width
        UIView.animate(withDuration: 0.3) { 
            self.layoutIfNeeded()
        }
    }
    
    @IBAction func searchButtonClick(_ sender: AnyObject) {
        searchTextField.resignFirstResponder()
        searchTextFieldRightConstranit.constant = 0
        UIView.animate(withDuration: 0.3) {
            self.layoutIfNeeded()
        }
    }
    
    //设置一个类方法创建
    class func searchView() ->SearchView {
        return UINib(nibName: "SearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last! as! SearchView
    }
    
    //设置文本框属性
    override func awakeFromNib() {
        searchTextField.layer.borderWidth = 5
        searchTextField.layer.borderColor = UIColor.lightGray.cgColor
        searchTextField.layer.cornerRadius = 10
        searchTextField.layer.masksToBounds = true
    }
}
